#!/usr/bin/env python

# -------------------------------
# projects/python/collatz/main.py
# Copyright (C) 2009
# Glenn P. Downing
# -------------------------------

# To run the program
#     main.py < Collatz.in > Collatz.out

# To document the program
#     pydoc -w main

# -------
# globals
# -------

i = 0 # input: don't change after reading
j = 0 # input: don't change after reading
v = 0 # output

# -----------
# InputReader
# -----------

class InputReader (object) :
    def read (self) :
        return raw_input()

# ------------
# OutputWriter
# ------------

class OutputWriter (object) :
    def write (self, *a) :
        for w in a :
            print w,
        print

# -------
# my_read
# -------

def my_read (reader) :
    """
    reads an int into i and j
    return true if that succeeds, false otherwise
    """
    global i
    global j
    try :
        s = reader.read()
    except EOFError :
        return False
    l = s.split()
    i = int(l[0])
    j = int(l[1])
    return True

# -------
# my_eval
# -------

def my_eval () :
    """
    computes the max cycle length in the range [i, j]
    and stores the result in v
    """
    global v
    v = 0
    finalv = 0
    myarr = {}
    anarr = {}
    
    """
    sets up the start/end points of the sequence to be tested
    """
    if i <= j :
     a = i
     b = j + 1
    else :
     a = j
     b = i + 1

    """
    starts iterating through the range
    """
    for c in range (a,b) :
    
     d = c
     while d != 1 :
     # start iteration for current number
      if d in myarr :                                          
      # if the value is present in the dictionary just take it from there
       finalv = myarr[d] + finalv - 1           # finalv is the cycle length
       d = 1                                              #ends the while loop without searching anymore
      else :
      # if the value is not present in the dictionary
       anarr[d] = finalv                 # uses in the intermediate values of the current number
       if d % 2 == 0 :                   # checks if the current d is even
        d = d / 2                             # divides by 2 if so
        finalv += 1                        # adds 1 to the current cycle length
       else :
        d = (3 * d + 1) / 2                        # multiplies by 3 and adds 1, then divides by 2 if odd
        finalv += 2                               # increases the cycle length by 2 (optimization, 3n+1 always yields an even number)
     # end while, stop iterations for current number, cycle length is found
     myarr[c] = finalv+1                        # final cycle length for the current  value c
     
     for k, val in anarr.iteritems():       # iterates through the other dictionary for the intermediate values    
      myarr[k] = myarr[c] - val              # cycle length = final c.l. - cycles before element
      
     anarr.clear()  # clears the other dictionary of all entries
     if myarr[c] > v :                      
      v = myarr[c]                          # keeps just the maximum cycle length
     
     finalv = 0                                 # clears the counter for the current cycle length

# --------
# my_print
# --------

def my_print (writer) :
    """
    writes the values of i, j, and v
    """
    writer.write(i, j, v)

# ----
# main
# ----

def main () :
    """
    runs the program
    """
    while my_read(InputReader()) :
        my_eval()
        my_print(OutputWriter())

if __name__ == "__main__" :
    main()
